import java.util.ArrayList;

public class Data{        

        private int stn;
        private String date;
        private String time;
        private double temp;
        private double dewp;        
        private double stp;
        private double slp;
        private double visib;
        private double wdsp;
        private double prcp;            
        private double sndp;    
        private String frshtt;
        private double cldc;    
        private int wnddir;
        private int[] maxBytes = {6,10,8,5,5,5,5,6,6,5,5,5,6,5,4,3};
       
        
        /**
         * Gets the station id.
         *
         * @return the station id
         */
        public int getStn() {
                return stn;
        }


        /**
         * Sets the station id.
         *
         * @param stationID the new station id
         */
        public void setStn(int stn) {
                this.stn = stn;
        }


        /**
         * Gets the date.
         *
         * @return the date
         */
        public String getDate() {
                return date;
        }


        /**
         * Sets the date.
         *
         * @param date the new date
         */
        public void setDate(String date) {              
                this.date = date;
        }


        /**
         * Gets the time.
         *
         * @return the time
         */
        public String getTime() {
                return time;
        }


        /**
         * Sets the time.
         *
         * @param time the new time
         */
        public void setTime(String time) {
                this.time = time;
        }


        /**
         * Gets the temp.
         *
         * @return the temp
         */
        public double getTemp() {
                return temp;
        }


        /**
         * Sets the temp.
         *
         * @param temp the new temp
         */
        public void setTemp(double temp) {
                this.temp = temp;
        }


        /**
         * Gets the dewp.
         *
         * @return the dewp
         */
        public double getDewp() {
                return dewp;
        }


        /**
         * Sets the dewp.
         *
         * @param dewp the new dewp
         */
        public void setDewp(double dewp) {
                this.dewp = dewp;
        }

        /**
         * Gets the stp.
         *
         * @return the stp
         */
        public double getStp() {
                return stp;
        }


        /**
         * Sets the stp.
         *
         * @param stp the new stp
         */
        public void setStp(double stp) {
                this.stp = stp;
        }


        /**
         * Gets the slp.
         *
         * @return the slp
         */
        public double getSlp() {
                return slp;
        }


        /**
         * Sets the slp.
         *
         * @param slp the new slp
         */
        public void setSlp(double slp) {
                this.slp = slp;
        }


        /**
         * Gets the visib.
         *
         * @return the visib
         */
        public double getVisib() {
                return visib;
        }


        /**
         * Sets the visib.
         *
         * @param visib the new visib
         */
        public void setVisib(double visib) {
                this.visib = visib;
        }


        /**
         * Gets the wdsp.
         *
         * @return the wdsp
         */
        public double getWdsp() {
                return wdsp;
        }


        /**
         * Sets the wdsp.
         *
         * @param wdsp the new wdsp
         */
        public void setWdsp(double wdsp) {
                this.wdsp = wdsp;
        }


        /**
         * Gets the prcp.
         *
         * @return the prcp
         */
        public double getPrcp() {
                return prcp;
        }


        /**
         * Sets the prcp.
         *
         * @param prcp the new prcp
         */
        public void setPrcp(double prcp) {
                this.prcp = prcp;
        }


        /**
         * Gets the sndp.
         *
         * @return the sndp
         */
        public double getSndp() {
                return sndp;
        }


        /**
         * Sets the sndp.
         *
         * @param sndp the new sndp
         */
        public void setSndp(double sndp) {
                this.sndp = sndp;
        }


        /**
         * Gets the frshtt.
         *
         * @return the frshtt
         */
        public String getFrshtt() {
                return frshtt;
        }


        /**
         * Sets the frshtt.
         *
         * @param frshtt the new frshtt
         */
        public void setFrshtt(String frshtt) {
                this.frshtt = frshtt;
        }


        /**
         * Gets the cldc.
         *
         * @return the cldc
         */
        public double getCldc() {
                return cldc;
        }


        /**
         * Sets the cldc.
         *
         * @param cldc the new cldc
         */
        public void setCldc(double cldc) {
                this.cldc = cldc;
        }


        /**
         * Gets the wnddir.
         *
         * @return the wnddir
         */
        public int getWnddir() {
                return wnddir;
        }


        /**
         * Sets the wnddir.
         *
         * @param wnddir the new wnddir
         */
        public void setWnddir(int wnddir) {
        	if(wnddir>360){
        		wnddir =360;
        	}else if(wnddir<0){
        		wnddir = 0;
        	}        		
        	this.wnddir = wnddir;
        }


        /**
         * Instantiates a new data.
         */
        public Data(){
                
        }
        
        /**
         * For debugging purposes. Returns all the data separated by new line
         * @return measurement the data in a nice way to see
         */
        public String toString(){
                String measurement = "";
                
                measurement += "Datum: " + date + "\n";
                measurement += "Tijd: " + time + "\n";
                measurement += "Temperatuur: " + temp + "\n";
                measurement += "Dauwpunt: " + dewp + "\n";
                measurement += "Luchtdruk 1: " + stp + "\n";
                measurement += "Luchtdruk 2: " + slp + "\n";
                measurement += "Zichtbaarheid: " + visib + "\n";
                measurement += "Windsnelheid: " + wdsp + "\n";
                measurement += "Neerslag: " + prcp + "\n";
                measurement += "Gevallen sneeuw: " + sndp + "\n";
                measurement += "Gebeurtenissen: " + frshtt + "\n";
                measurement += "Bewolking: " + cldc + "\n";
                measurement += "Windrichting: " + wnddir + "\n";
                
                return measurement;
        }
        
        /**
         * Returns the data with the right length and in one string
         * @return values all the data in one string
         */
        public synchronized String getAllData(){
                String values = "";
                values += resizeData(maxBytes[3], temp+"", true);
                values += resizeData(maxBytes[4], dewp+"", true);               
                values += resizeData(maxBytes[7], stp+"", true);
                values += resizeData(maxBytes[8], slp+"", true);
                values += resizeData(maxBytes[9], visib+"", true);
                values += resizeData(maxBytes[10], wdsp+"", true);
                values += resizeData(maxBytes[11], prcp+"", true);
                values += resizeData(maxBytes[12], sndp+"", true);
                values += resizeData(maxBytes[13], frshtt+"", false);
                values += resizeData(maxBytes[14], cldc+"", true);
                values += resizeData(maxBytes[15], wnddir+"", false);
                return values;
        }
        
        /**
         * Returns the data resized by a specific length        
         * @param length
         * @param x
         * @param decimal
         * @return
         */
        private String resizeData(int length, String x, boolean decimal) {
        	
        	String value ="";
        	if(decimal){
        		double val = Math.round(Double.parseDouble(x)*10)/10.0;
            	value += Double.toString(val);
        	} else{
        		value += x;
        	}
        	

        	while(value.length() < length) {
                value += " ";
        	}    
        	if(value.length()>length){
        		value = x.substring(0, length);
        	}
        	value = value.replace(",", ".");
            return value;
        }
        
        /**
         * Returns all the data in a array
         * @return data Array with all the weatherdata
         */
        public ArrayList<Object> getDataArray(){
                ArrayList<Object> data = new ArrayList<Object>();
                data.add(0, getStn());
                data.add(1, getDate());
                data.add(2, getTime());
                data.add(3, getTemp());
                data.add(4, getDewp());
                data.add(5, getStp());
                data.add(6, getSlp());
                data.add(7, getVisib());
                data.add(8, getWdsp());
                data.add(9, getPrcp());
                data.add(10, getSndp());
                data.add(11, getFrshtt());
                data.add(12, getCldc());
                data.add(13, getWnddir());              
                return data;
        }

}
